import ErrorComp from '@/components/common/error-comp';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import HomePageList from '@/components/user/home-page-list';
import HotShop from '@/components/user/hot-shop';
import NearbyShopList from '@/components/user/nearby-shop-list';
import RecommendShopList from '@/components/user/recommend-shop-list';
import { pageSchema } from '@/service/query/schema/common';
import type { SearchParams } from '@/service/type/common';
import { z } from 'zod';

export const metadata = {
  title: '外卖',
};

const PageSchema = pageSchema.extend({
  type: z.enum(['nearby', 'recommend']).default('recommend'),
  addressId: z.coerce.number().int().positive().optional(),
  deliverRange: z.coerce.number().int().positive().optional().default(5000),
  keywords: z.string().optional(),
});

export default async function Page({
  searchParams,
}: {
  searchParams: SearchParams;
}) {
  const parsed = PageSchema.safeParse(await searchParams);
  if (!parsed.success) return <ErrorComp message="参数错误" />;

  return (
    <div className="space-y-8 pb-10 px-16 pt-20 min-h-screen shadow-lg">
      <HotShop />
      <hr />
      <HomePageList
        recommendList={<RecommendShopList searchParams={parsed.data} />}
        nearbyList={<NearbyShopList searchParams={parsed.data} />}
      />
    </div>
  );
}
